package gov.tax.rti.base.controller;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.bstek.dorado.annotation.DataProvider;
@Transactional(propagation=Propagation.REQUIRED,readOnly=true)
@Component("gdgs.base.mutilSelectDropdownController")
public class MutilSelectDropdownController {

	@DataProvider
	public Collection<Map<String, String>> getYear(String start,String end) {
		Collection<Map<String, String>> ls = new ArrayList<Map<String, String>>();
		if(StringUtils.isEmpty(start) && StringUtils.isEmpty(end)){
			int year = Calendar.getInstance().get(Calendar.YEAR);
			for (int i = year - 10, len = year ; i <= len; i++) {
				Map<String, String> yearInfo = new HashMap<String, String>();
				yearInfo.put("name", i + "");
				yearInfo.put("label", i + "年");
				ls.add(yearInfo);
			}
			 
		}else if(StringUtils.isNotEmpty(start) && StringUtils.isNotEmpty(end)){
			int startYear =Integer.parseInt(start);
			int endYear =Integer.parseInt(end);
			if(endYear > startYear){
				for(int i = startYear;i<=endYear;i++){
					Map<String, String> yearInfo = new HashMap<String, String>();
					yearInfo.put("name", i + "");
					yearInfo.put("label", i + "年");
					ls.add(yearInfo);
				}
			}
		}
		return ls;
	}

	@DataProvider
	public Collection<Map<String, String>> getHalfYear(String year) {
		Collection<Map<String, String>> ls = new ArrayList<Map<String, String>>();
		Map<String, String> halfYearInfo = new HashMap<String, String>();
		halfYearInfo.put("name", year + "0");
		halfYearInfo.put("label", year+"年上半年");
		halfYearInfo.put("dm", "0");
		halfYearInfo.put("year", year);
		ls.add(halfYearInfo);
		halfYearInfo = new HashMap<String, String>();
		halfYearInfo.put("name", year + "1");
		halfYearInfo.put("label", year+"年下半年");
		halfYearInfo.put("dm", "1");
		halfYearInfo.put("year", year);
		ls.add(halfYearInfo);
		return ls;
	}

	@DataProvider
	public Collection<Map<String, String>> getSeason(String year,
			String halfYear) {
		Collection<Map<String, String>> ls = new ArrayList<Map<String, String>>();
		if ("0".equals(halfYear)) {
			Map<String, String> seasonInfo = new HashMap<String, String>();
			seasonInfo.put("name", year + "01");
			seasonInfo.put("label", year+"年第一季度");
			seasonInfo.put("dm", "1");
			seasonInfo.put("year", year);
			ls.add(seasonInfo);
			seasonInfo = new HashMap<String, String>();
			seasonInfo.put("name", year + "02");
			seasonInfo.put("label", year+"年第二季度");
			seasonInfo.put("dm", "2");
			seasonInfo.put("year", year);
			ls.add(seasonInfo);
		} else {
			Map<String, String> seasonInfo = new HashMap<String, String>();
			seasonInfo = new HashMap<String, String>();
			seasonInfo.put("name", year + "13");
			seasonInfo.put("label",year+"年第三季度");
			seasonInfo.put("dm", "3");
			seasonInfo.put("year", year);
			ls.add(seasonInfo);
			seasonInfo = new HashMap<String, String>();
			seasonInfo.put("name", year + "14");
			seasonInfo.put("label", year+"年第四季度");
			seasonInfo.put("dm", "4");
			seasonInfo.put("year", year);
			ls.add(seasonInfo);
		}
		return ls;
	}

	@DataProvider
	public Collection<Map<String, String>> getMonth(String year,String season) {
		Collection<Map<String, String>> ls = new ArrayList<Map<String, String>>();
		int seasonNum = Integer.parseInt(season);
		seasonNum = (seasonNum-1)*3+1;
		for (int i = seasonNum; i <= seasonNum+2; i++) {
			Map<String, String> monthInfo = new HashMap<String, String>();
			if (i < 10) {
				monthInfo.put("name", year +"-"+ "0" + i);
				monthInfo.put("label", year + "年" + "0" + i + "月");

			} else {
				monthInfo.put("name", year +"-"+ i);
				monthInfo.put("label", year + "年" + i + "月");
			}
			ls.add(monthInfo);
		}
		return ls;
	}
	@DataProvider
	public Collection<Map<String, String>> getMonth(String year) {
		Collection<Map<String, String>> ls = new ArrayList<Map<String, String>>();
 
		for (int i = 1; i <= 12; i++) {
			Map<String, String> monthInfo = new HashMap<String, String>();
			if (i < 10) {
				monthInfo.put("name", year +"-"+ "0" + i);
				monthInfo.put("label", year + "年" + "0" + i + "月");
				
			} else {
				monthInfo.put("name", year +"-"+ i);
				monthInfo.put("label", year + "年" + i + "月");
			}
			ls.add(monthInfo);
		}
		return ls;
	}


}
